package com.example.manager.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.viewpager.widget.PagerAdapter;


import com.bumptech.glide.Glide;
import com.example.manager.ui.HomeActivity;
import com.example.manager.R;

import java.util.List;

public class SlidePagerAdapter extends PagerAdapter {

    private Context context;
    private List<String> imageList;

    public SlidePagerAdapter(HomeActivity context, List<String> imageList) {
        this.context = (Context) context;
        this.imageList = imageList;
    }

    @Override
    public int getCount() {
        return imageList != null ? imageList.size() : 0;
    }


    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View itemView = LayoutInflater.from(context).inflate(R.layout.slide_item, container, false);

        ImageView imageView = itemView.findViewById(R.id.imageView);
        Glide.with(context).load(imageList.get(position)).into(imageView);

        container.addView(itemView);

        return itemView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
